package hamsterpolice.todo.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.format.Time;

public class ToDoItemFilter implements Parcelable {

	private User user;
	private Category category;
	private Time dueBefore, dueAfter;
	private boolean completed;
//add filter here
	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeParcelable(user, flags);
		dest.writeParcelable(category, flags);
		dest.writeLong(dueBefore!=null ? dueBefore.toMillis(false) : 0);
		dest.writeLong(dueAfter!=null ? dueAfter.toMillis(false) : 0);
		dest.writeInt(completed ? 1 : 0);
	}

	public static final Parcelable.Creator<ToDoItemFilter> CREATOR = new Parcelable.Creator<ToDoItemFilter>() {
		public ToDoItemFilter createFromParcel(Parcel in) {
			return new ToDoItemFilter(in);
		}

		public ToDoItemFilter[] newArray(int size) {
			return new ToDoItemFilter[size];
		}
	};

	private ToDoItemFilter(Parcel in) {
		
		user = in.readParcelable(null);
		category = in.readParcelable(null);

		long lDueBefore = in.readLong();
		if (lDueBefore > 0) {
			dueBefore = new Time();
			dueBefore.set(lDueBefore);
		}

		long lDueAfter = in.readLong();
		if (lDueAfter > 0) {
			dueAfter = new Time();
			dueAfter.set(lDueAfter);
		}

		completed = in.readInt() == 0 ? false : true;
	}

	public ToDoItemFilter(User user) {
		this.user = user;
	}

	public User getUser() {
		return user;
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Category catergory) {
		this.category = catergory;
	}

	public Time getDueBefore() {
		return dueBefore;
	}

	public void setDueBefore(Time dueBefore) {
		this.dueBefore = dueBefore;
	}

	public Time getDueAfter() {
		return dueAfter;
	}

	public void setDueAfter(Time dueAfter) {
		this.dueAfter = dueAfter;
	}

	public boolean isCompleted() {
		return completed;
	}

	public void setCompleted(boolean completed) {
		this.completed = completed;
	}
}
